package com.ruoyi.system.service.impl;


import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.core.constant.CacheConstants;
import com.ruoyi.common.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysOperUrlMapper;
import com.ruoyi.system.api.domain.SysOperUrl;
import com.ruoyi.system.service.ISysOperUrlService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Collection;
import java.util.List;

/**
 * 日志配置Service业务层处理
 * 
 * @author lcj
 * @date 2025-05-16
 */
@Service
public class SysOperUrlServiceImpl extends ServiceImpl<SysOperUrlMapper, SysOperUrl> implements ISysOperUrlService {

    @Autowired
    private RedisService redisService;

    @Override
    public void getRefreshCache() {
        List<SysOperUrl> list = this.list(Wrappers.<SysOperUrl>lambdaQuery().eq(SysOperUrl::getStatus,1));
        //查询keys
        Collection<String>  collection= redisService.keys(CacheConstants.LOG_CONFIG+"*");
        if (!collection.isEmpty()){
            for (String s : collection) {
                //删除缓存
                redisService.deleteObject(s);
            }
        }
        if (CollectionUtil.isNotEmpty(list)) {
            list.forEach(item->{
                //放入缓存
                redisService.setCacheObject(CacheConstants.LOG_CONFIG+item.getApiUrl(), item);
            });
        }
    }
}
